package wt.hpad.activity.order;

import android.support.v4.app.Fragment;

import java.util.ArrayList;
import java.util.List;

import wt.hpad.model.bean.Dish;
import wt.hpad.model.bean.DishType;
import wt.hpad.model.local.DBHelper;

/**
 * Created by wt on 12.26.
 */

public class OrderPresenter implements OrderContract.Presenter {

    OrderContract.View mOrderView;

    public OrderPresenter(OrderContract.View orderView) {
        mOrderView = orderView;
        mOrderView.setPresenter(this);
    }

    @Override
    public void subscribe() {

    }

    @Override
    public void unsubscribe() {

    }

    @Override
    public List<DishType> getDishTypes() {
        return DBHelper.queryAllDishType();
    }

    @Override
    public List<Fragment> initTypeFragments() {
        List<Fragment> fragments = new ArrayList<>();
        // 查询所有的 dishType 为每个 dishType 对应的 RecyclerView 建立对应的 适配器
        List<DishType> dishTypes = getDishTypes();
        for (DishType dishType : dishTypes) {
            int dishTypeCode = dishType.dishTypeCode;
            List<Dish> dishes = DBHelper.queryDishForType(dishTypeCode);
            // 按照适配器建立相应 包含 RecyclerView 的 Fragment
            OrderFragment orderFragment = new OrderFragment();
            // 把这些 数据源 装载载进入  Fragment
            orderFragment.setDataSource(dishes);
            fragments.add(orderFragment);
        }
        return fragments;
    }
}
